package com.itheima.api.map.demo04;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

public class MapTraverseDemo_1 {

    public static void main(String[] args) {

        Map<String, String> map = new HashMap<>();
        map.put("蓝湛", "蓝忘机");
        map.put("魏婴", "魏无羡");
        map.put("蓝涣", "蓝曦臣");
        System.out.println(map);

        Set<String> keySet = map.keySet();

            //两次调用iterator.next()方法，顺序乱了
//        Iterator<String> iterator = keySet.iterator();
//        while (iterator.hasNext()){
//            System.out.println(iterator.next() + "-1-" + map.get(iterator.next()));
//        }

        Iterator<String> iterator1 = keySet.iterator();
        while (iterator1.hasNext()){
            String key = iterator1.next();
            String value = map.get(key);
            System.out.println(key + "-2-" + value);
        }

        for (String key : keySet){
            System.out.println(key + "-3-" + map.get(key));
        }

        map.forEach(new BiConsumer<String, String>() {
            @Override
            public void accept(String s, String s2) {
                System.out.println(s + "-4-" + s2);
            }
        });

        map.forEach((key, value) -> System.out.println(key + "-5-" + value));
    }
}
